<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function deepCopy(obj1) {
        //     var obj2 = Object.prototype.toString.call(obj1) === '[object Array]' ? [] : {};
        //     for (var key in obj1) {
        //         obj2[key] = obj1[key];
        //     }
        //     return obj2;
        // }

        function deepCopy(obj1) {
            var obj2 = Object.prototype.toString.call(obj1) === '[object Array]' ? [] : {};
            for (var key in obj1) {
                if (obj1.hasOwnProperty(key)) {
                    if (typeof obj1[key] === 'object') {
                        obj2[key] = deepCopy(obj1[key]);
                    } else {
                        obj2[key] = obj1[key];
                    }
                }
            }
            return obj2;
        }
        Object.prototype.height = '178cm';
        var obj3 = {
            name: '王俊凯',
            age: 18,
            hoppy: {
                name1: '篮球',
                name2: '足球'
            }
        }
        var obj4 = deepCopy(obj3);
        console.log(obj4);
        obj4.hoppy.name1 = '羽毛球';
        console.log(obj3);

    </script>
</body>
</html>